package GUI;

import javax.swing.JPanel;
import javax.swing.JLabel;
import java.awt.Font;
import java.awt.event.ActionEvent;
import javax.swing.SwingConstants;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import MessagePacks.MessagePack;
import MessagePacks.UpdatePack;

/**
 *@author Juan Alapin - 324507516
 *@author Giora Yaffe - 036551281
 *@author Shachar Gritzman - 300174026
 *@author Nir Porat - 021515580
*/

public class TimeEstimation extends EstimatorMenuScreen{
	
	private static final long serialVersionUID = 1L;
	private JTextField daysField;
	private JButton btnApply;
	private MainGUI mainGui;
	private int days;
	private UpdatePack d,activeStat;
	
	
	public TimeEstimation(MainGUI mainGui){
		super( mainGui);
		this.mainGui=mainGui;
		
		getproc();
				
		getContentPane().setFont(new Font("Dialog", Font.BOLD, 16));
		
		JPanel panel = new JPanel();
		panel.setBounds(0, 0, 884, 40);
		getContentPane().add(panel);
		
		JLabel lblTimeEstimation = new JLabel("Time Estimation");
		lblTimeEstimation.setFont(new Font("Dialog", Font.BOLD, 16));
		panel.add(lblTimeEstimation);
		
		JLabel lblEnterTimeEstimation = new JLabel("Enter Time Estimation:");
		lblEnterTimeEstimation.setHorizontalAlignment(SwingConstants.LEFT);
		lblEnterTimeEstimation.setFont(new Font("Tahoma", Font.PLAIN, 17));
		lblEnterTimeEstimation.setBounds(228, 214, 192, 40);
		getContentPane().add(lblEnterTimeEstimation);
		
		daysField = new JTextField();
		daysField.setBounds(410, 226, 74, 23);
		getContentPane().add(daysField);
		daysField.setColumns(10);
		
		
		setBtnApply();
		
		JLabel lblDays = new JLabel("Days");
		lblDays.setFont(new Font("Tahoma", Font.PLAIN, 15));
		lblDays.setBounds(494, 224, 53, 23);
		getContentPane().add(lblDays);
		
		JLabel lblChooseProcess = new JLabel("Process number ");
		lblChooseProcess.setHorizontalAlignment(SwingConstants.LEFT);
		lblChooseProcess.setFont(new Font("Tahoma", Font.PLAIN, 17));
		lblChooseProcess.setBounds(228, 163, 162, 40);
		getContentPane().add(lblChooseProcess);
		
	}

	public JButton getBtnApply() {
		return btnApply;
	}
 
	public void getproc(){
	
		int proc= mainGui.process.getprocessID();
		JLabel lblNewLabel = new JLabel();
		lblNewLabel.setBounds(410, 172, 61, 29);
		getContentPane().add(lblNewLabel);
		lblNewLabel.setText(Integer.toString(proc));
			}
	
	public void setBtnApply() {
		btnApply = new JButton("Apply");
		btnApply.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				int proc= mainGui.process.getprocessID();
				days = Integer.parseInt(daysField.getText());
				d= new UpdatePack(MessagePack.estimationtime);
				d.setTime(days);
				d.setProcId(proc);
				UpdateStatus();
				mainGui.client.handleMessageFromClientUI(d);
				btnApply.setEnabled(false);
				}
			});
		btnApply.setBounds(458, 299, 89, 23);
		getContentPane().add(btnApply);
		
	}
	public void UpdateStatus() {
	activeStat = new UpdatePack(MessagePack.updateStatus);
	  activeStat.setStatus("Waiting For Time Approval");
	  activeStat.setProcId(mainGui.process.getprocessID());
	  mainGui.client.handleMessageFromClientUI(activeStat);
	}
	

}
